package com.boot.controller;

import com.boot.entity.User;
import com.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/list")
    public ModelAndView list(){
        ModelAndView mv = new ModelAndView("list");

        List<User> users = userService.list();

        mv.addObject("users",users);

        return mv;
    }

    @RequestMapping("/deleteById")
    public String deleteById(Long id){
        userService.deleteById(id);
        return "redirect:/user/list";
    }

}
